<template>
  <view class="container screen-width">
    <view class="list-content" v-if="searchList.length">
      <view
        class="list-item"
        v-for="(item,index) in searchList"
        :key="index"
        @click="toDetail(item.companyId,item.companyName)"
      >
        <view class="company-name">{{item.companyName}}</view>
        <view class="com-info flex space-between">
          <view>法定代表人：{{item.legalPerson}}</view>
          <view>注册资本：{{item.registeredCapital}}</view>
        </view>
        <view class="com-info">成立日期：{{item.establishTime}}</view>
        <view class="com-info">所属行业：{{item.industry}}</view>
        <view class="com-info">地址：{{item.companyAddress}}</view>
      </view>
      <van-divider v-show="searchList.length && total < total + 1">我也是有底线的</van-divider>
    </view>
    <van-divider v-else>我也是有底线的</van-divider>

    <view
      v-if="searchList.length && searchList.length>0"
      class="bottom-btn screen-width"
      @click="toClear"
    >清除历史</view>
    <Festival></Festival>
  </view>
</template>
<script>
import { deleteSearch, searchHistoryList } from "../../util/api/company.js";
export default {
  data() {
    return {
      search: {
        pageNo: 1,
        pageSize: 10
      },
      total: 0,
      searchList: []
    };
  },
  onLoad() {
    this.getList();
  },
  onReachBottom() {
    if (this.searchList.length >= this.total) return;
    this.search.pageNo += 1;
    this.getList();
  },
  methods: {
    getList() {
      searchHistoryList(this.search).then(res => {
        this.searchList = this.searchList.concat(res.result.records);
        this.total = res.result.total;
      });
    },
    toDetail(id, name) {
      uni.navigateTo({
        url: `/pages/enterpriseDetails/brand_detail?id=${id}&type=1&name=${name}&liIndex=0&showNew=true`
      });
    },
    toClear() {
      let _this = this;
      uni.showModal({
        title: "提示",
        content: "确定清空历史记录",
        cancelText: "考虑一下",
        success(res) {
          if (res.confirm) {
            deleteSearch().then(res => {
              if (res.code === 200) {
                uni.showToast({
                  title: "操作成功",
                  duration: 2000,
                  icon: "none"
                });
                _this.getList();
              }
            });
          }
        }
      });
    }
  }
};
</script>
<style lang="less" scoped>
.container {
  .list-content {
    width: 100%;
    padding: 0 30upx 60upx 30upx;
    box-sizing: border-box;
    .list-item {
      margin-top: 20upx;
      box-shadow: 0px 1px 7px 0px rgba(132, 202, 187, 0.3);
      background: #fff;
      padding: 10upx 15upx;
      box-sizing: border-box;
      .company-name {
        font-size: 34upx;
        font-weight: 600;
      }
      .com-info {
        margin-top: 10upx;
        color: #999;
        font-size: 24upx;
      }
    }
  }
  .bottom-btn {
    position: fixed;
    bottom: 0;
    width: 100%;
    padding: 25upx 0;
    text-align: center;
    background: #1678ff;
    color: white;
    font-size: 16px;
  }
}
</style>